#Include "../common/log.ahk"
#Include "../common/bt.ahk"
#SingleInstance Force
SendMode "Input"
SetKeyDelay 0

Init()

esIni := FileExist(iniPath)
if(esIni) {
    ConfigRead()
} else
{
    InIWriter()
}

myGui()

^F1:: {
    MouseGetPos &MouseX, &MouseY
    color := PixelGetColor(MouseX, MouseY)

}

;初始化
Init() 
{
    global codeKey := "XButton2"
    global iniPath := "./xj.ini"
    i:=0
    global keymap := Map()
    Loop 5
    {
        keymap[i] := {
            keyname: "",
            keysleep: 52,
            color:"",
            x:0,
            y:0,
            m:1,
        }
        i := i+1
    }

}

;读取配置文件
ConfigRead() 
{

}

; 写入配置
InIWriter() 
{
    i := 0
    Loop 5 
    {
        IniWrite keymap[i].keyname, iniPath, i, "key"
        i := i+1
    }
    str:="init config ....."
    Log.log(&str)
}

myGui() {
    MyGui := Gui()
    MyGui.Add("Text", "ym+7 xm+0 Section", "Ctrl+F1取色, 侧键1触发宏 侧键2会触发ss，更精细的调整期待后续版本`n ")

    MyGui.Add("Text", "ym+27 xm+0 Section", "选择按键后，点击重新加载触发配置`n ")

    MyGui.Add("Text", "xs")
    MyGui.Add("Text", "y+10 xm+5 w25", "序号")
    MyGui.Add("Text", "x+30 w50", "健值")
    i := 0
    Loop 5 
    {
        edit3 := MyGui.Add("Text", "y+10 xm+5 w25", i)
        edit0 := MyGui.Add("Edit", "x+30 w50")
        edit0.value:=keymap[i].keyname
        edit1 := MyGui.Add("Edit", "x+10 w50" )
        edit1.value:=keymap[i].keysleep
        edit2 := MyGui.Add("Text", "x+10 w50", "取色值" keymap[i].color)
        edit3 := MyGui.Add("Text", "x+10 w10", keymap[i].x)
        edit4 := MyGui.Add("Text", "x+10 w10", keymap[i].y)
        i := i+1
    }
    MyGui.Add("Text", "xs")
    MyBtn := MyGui.AddButton("w80", "重新加载")
    MyBtn.OnEvent("Click", loadAhk) ; 当点击时, 调用 MyBtn_Click.
    MyGui.Show
}

loadAhk(*) {
    InIWriter()
    Reload
}